package com.yn.iotxiao.controller.User;

import com.yn.iotxiao.Utils.JsonHelper;
import com.yn.iotxiao.authorize.Authorize;
import com.yn.iotxiao.request.PageRequest;
import com.yn.iotxiao.response.ResponseResult;
import com.yn.iotxiao.sql.services.Face.FaceInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/face")
@Slf4j
@RestController
@ResponseResult
public class FaceController {

    @Autowired
    FaceInfoService fService;

    @PostMapping("/list")
    @Authorize
    public Object getList(@RequestBody PageRequest request) {
        var list = fService.getListPage(request.getSearchKey(),request.getPage(),request.getPageSize());
        int total = fService.getTotal(request.getSearchKey());

        return JsonHelper.create("total",total,"list",list);
    }

    @DeleteMapping("/{uid}")
    public String deleteWithUid(@PathVariable String uid) {
        int result = fService.deleteWithKey(uid);
        if (result > 0) {
            return "删除成功";
        }
        throw new RuntimeException("删除失败");
    }
}
